﻿/**********************************************************************************
 * Project Name :   
 * Remarks      :  
 * Class Name   :  SqlUtility
 * Version      :  v1.0.0.0 
 * Author       :  Joey Liang 
 * Description  : 
 * Created Time :  2013/8/4 17:08:27
 * Update Man   :  Joey Liang
 * Update Time  :  2013/8/4 17:08:27
************************************************************************/

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IdleTest.DemoBeTest
{
    public class SqlUtility
    {        
        /// <summary>
        /// 获取数据对象的字符串值，无值则返回空字符串
        /// </summary>
        public static string GetDataColumnValue(object obj)
        {
            if (DBNull.Value.Equals(obj))
            {
                return string.Empty;
            }

            return string.Format("{0}", obj);
        }

        /// <summary>
        /// 判断 DataSet是否为 Null 或 Empty
        /// </summary>
        /// <param name="set">The set.</param>
        /// <returns>判断结果</returns>
        public static bool IsDataSetNullOrEmpty(DataSet set)
        {
            bool result = true;
            if (set == null || set.Tables.Count < 1)
            {
                return result;
            }

            foreach (DataTable dt in set.Tables)
            {
                if (!IsDataTableNullOrEmpty(dt))  //有一个Table不为空
                {
                    return false;
                }
            }

            return result;
        }

        /// <summary>
        /// 判断 DataTable是否为 Null 或 Empty
        /// </summary>
        /// <param name="table">The table.</param>
        /// <returns>判断结果</returns>
        public static bool IsDataTableNullOrEmpty(DataTable table)
        {
            return table == null || table.Rows.Count < 1 || table.Columns.Count < 1;
        }
    }
}
